import MySQLdb

no = int(input('部门编号: '))

conn = MySQLdb.connect(host='47.104.31.138', port=3306,
                       database='hrs', charset='utf8',
                       user='luohao', password='Luohao.618')
try:
    with conn.cursor() as cursor:
        result = cursor.execute(
            'delete from tb_dept where dno=%s',
            (no, )
        )
        if result == 1:
            print('删除部门成功!!!')
    # 第四步：操作成功，提交之前的操作
    conn.commit()
except MySQLdb.MySQLError as err:
    print(err)
    # 第四步：操作失败，回滚之前的操作
    conn.rollback()
finally:
    # 第五步：关闭连接，释放资源
    conn.close()
